package concurrent.newa;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.concurrent.CompletableFuture;

public class TestFactory {

    Account account = new Account();

    @Test(invocationCount = 30000)
    private void t1() throws InterruptedException {



        Runnable r1 = () -> {
            account.modify(1000);
        };


        Runnable runnable = () -> {

            Thread t1 = new Thread(r1);
            t1.start();

            Thread t2 = new Thread(r1);
            t2.start();
        };


        CompletableFuture.runAsync(runnable)
            .thenAccept(res -> {
                Assert.assertEquals(3000, account.getBalance());
            });




    }




}
